<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('店铺小程序列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="case-form">
                <div class="select-list">
                    <ul>
                        <li>
                            店铺名称：<input type="text" name="shopName"/>
                        </li>
                        <li>
                            小程序名称：<input type="text" name="appletName"/>
                        </li>
                        <li>
                            <p style="width: 110px">营业状态： </p>
                            <select name="isEnable" th:with="type=${@dict.getType('open_status')}">
                                <option value="">全部</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <p style="width: 110px">审核状态： </p>
                            <select name="reviewStatus" th:with="type=${@dict.getType('applet_review_status')}">
                                <option value="">全部</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" target="_blank" href="/back/wechatOpen/auth" shiro:hasPermission="back:shopApplet:auth">扫码授权
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('back:wechatOpen:edit')}]];
    var commitFlag = [[${@permission.hasPermi('back:wechatOpen:commit')}]];
    var detailFlag = [[${@permission.hasPermi('back:wechatOpen:authInfo')}]];
    var submitAuditFlag = [[${@permission.hasPermi('back:wechatOpen:submitAudit')}]];
    var speedupAuditFlag = [[${@permission.hasPermi('back:wechatOpen:speedupAudit')}]];
    var rollbackAuditFlag = [[${@permission.hasPermi('back:wechatOpen:rollbackAudit')}]];
    var backFlag = [[${@permission.hasPermi('back:wechatOpen:back')}]];
    var releaseAuditFlag = [[${@permission.hasPermi('back:wechatOpen:releaseAudit')}]];
    const appletDemoStatusDict = [[${@dict.getType('applet_demo_status')}]];
    var prefix = ctx + "back/wechatOpen";

    $(function () {
        var options = {
            url: prefix + "/searchAuthList",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            detailUrl: prefix + "/authInfo/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            sortName: "createTime",
            sortOrder: "desc",
            modalName: "小程序信息",
            height: 600,
            columns: [
                {
                    field: 'shopId',
                    title: '店铺ID'
                },
                {
                    field: 'commitId',
                    title: '体验版ID',
                    visible:false
                },
                {
                    field: 'auditid',
                    title: '审核ID',
                    visible:false
                },
                {
                    field: 'shopName',
                    title: '店铺名称',
                    visible:false
                },
                {
                    field: 'appletName',
                    title: '小程序名称'
                },
                {
                    field: 'shopLogo',
                    title: '小程序头像',
                    formatter: function (value, row, index) {
                        // var thumbUrl = value + '?imageView2/1/w/64/h/64';
                        return $.common.sprintf("<img class='img-circle img-sm' data-height='%s' data-width='%s' data-target='%s'  style='border-radius: 0;' src='%s' data-src='%s'/>", 400, 'auto', 'self', value, value);
                    }
                },
                {
                    field: 'demoQrCode',
                    title: '体验版(最新)',
                    formatter: function (value, row, index) {
                        return $.common.sprintf("<img class='img-circle img-sm' data-height='%s' data-width='%s' data-target='%s'  style='border-radius: 0;' src='%s' data-src='%s'/>", 400, 'auto', 'self', value, value);
                    }
                },
                {
                    field: 'statusDesc',
                    title: '体验版信息(最新)',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if(null != row.commitVersion){
                            actions.push('<label>版本号：</label><span style="font-weight: bold">' + row.commitVersion + '</span>');
                            actions.push('<br/><label>生成时间：</label><span style="font-weight: bold">' + row.commitCreateTime + '</span>');
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'statusDesc',
                    title: '审核版本信息',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if(null != row.auditid) {
                            actions.push('<label>版本号：</label><span style="font-weight: bold">' + row.auditVersion + '</span>');
                            actions.push('<br/><label>提审时间：</label><span style="font-weight: bold">' + row.auditCreateTime + '</span>');
                            actions.push('<br/><label>版本描述：</label><span style="font-weight: bold">' + row.commitDesc + '</span>');
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'statusDesc',
                    title: '线上版本信息',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if(null != row.releaseVersion) {
                            actions.push('<label>版本号：</label><span style="font-weight: bold">' + row.releaseVersion + '</span>');
                            actions.push('<br/><label>发布时间：</label><span style="font-weight: bold">' + row.releaseTime + '</span>');
                            actions.push('<br/><label>版本描述：</label><span style="font-weight: bold">' + row.releaseDesc + '</span>');
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'status',
                    title: '审核状态',
                    formatter: function (value, item, index) {
                        return $.table.selectDictLabel(appletDemoStatusDict, value);
                    }
                },
                {
                    field: 'statusDesc',
                    title: '说明'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-warning btn-xs ' + detailFlag + '" href="#" onclick="$.operate.detail(\'' + row.appId + '\')"><i class="fa fa-search">查看授权信息</i></a> ');
                        // actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit">编辑</i></a> ');
                        switch (parseInt(row.status)) {
                            case -1:
                                actions.push('<a class="btn btn-success btn-xs ' + commitFlag + '" href="#" onclick="commit(\'' + row.appId + '\')"><i class="fa fa-upload">生成体验版</i></a> ');
                                break;
                            case 1:
                                actions.push('<a class="btn btn-primary btn-xs ' + submitAuditFlag + '" href="#" onclick="submitAudit(\'' + row.commitId + '\')"><i class="fa fa-upload">提交审核</i></a> ');
                                actions.push('<a class="btn btn-success btn-xs ' + commitFlag + '" href="#" onclick="commit(\'' + row.appId + '\')"><i class="fa fa-upload">重新生成体验版</i></a> ');
                                break;
                            case 2:
                                actions.push('<a class="btn btn-success btn-xs ' + speedupAuditFlag + '" href="#" onclick="speedupAudit(\'' + row.auditid + '\',\'' + row.appId + '\')"><i class="fa fa-rocket">加急</i></a> ');
                                actions.push('<a class="btn btn-danger btn-xs ' + rollbackAuditFlag + '" href="#" onclick="rollbackAudit(\'' + row.appId + '\')"><i class="fa fa-close">撤回审核</i></a> ');
                                break;
                            case 3:
                                actions.push('<a class="btn btn-primary btn-xs ' + releaseAuditFlag + '" href="#" onclick="releaseAudit(\'' + row.appId + '\')"><i class="fa fa-check">发布</i></a> ');
                                actions.push('<a class="btn btn-success btn-xs ' + commitFlag + '" href="#" onclick="commit(\'' + row.appId + '\')"><i class="fa fa-upload">生成体验版</i></a> ');
                                break;
                            case 4:
                                actions.push('<a class="btn btn-danger btn-xs ' + backFlag + '" href="#" onclick="backLatest(\'' + row.appId + '\')"><i class="fa fa-backward">回退到上一版本</i></a> ');
                                actions.push('<a class="btn btn-success btn-xs ' + commitFlag + '" href="#" onclick="commit(\'' + row.appId + '\')"><i class="fa fa-upload">生成体验版</i></a> ');
                                break;
                            case 10:
                            case 11:
                                actions.push('<a class="btn btn-primary btn-xs ' + submitAuditFlag + '" href="#" onclick="submitAudit(\'' + row.commitId + '\')"><i class="fa fa-upload">重新提交审核</i></a> ');
                                actions.push('<a class="btn btn-success btn-xs ' + commitFlag + '" href="#" onclick="commit(\'' + row.appId + '\')"><i class="fa fa-upload">重新生成体验版</i></a> ');
                                break;
                            default:
                                break;
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /* 上传代码并生成体验版 */
    function commit(appId) {
        var url = prefix+'/commit/' + appId;
        $.modal.open("上传代码并生成体验版", url);
    }

    /* 批量上传代码并生成体验版 */
    function mutiCommit() {
        let rows = $.table.selectColumns('shopId');
        let shopIdStr = rows.join();
        $.modal.confirm("共选择了【"+rows.length+"】个小程序，请确认是否批量生成体验版？", function () {

        });
    }

    /* 提交代码审核 */
    function submitAudit(commitId) {
        var url = prefix+'/submitAudit/' + commitId;
        $.modal.open("提交代码审核", url);
    }

    /* 批量提交代码审核 */
    function mutiSubmitAudit() {
        let rows = $.table.selectColumns('shopId');
        let shopIdStr = rows.join();
        $.modal.confirm("共选择了【"+rows.length+"】个小程序，请确认是否批量生成体验版？", function () {

        });
    }

    /* 撤回审核 */
    function rollbackAudit(appId) {
        $.modal.confirm("单个帐号每天审核撤回次数最多不超过 5 次（每天的额度从0点开始生效），一个月不超过 10 次，请确认？", function () {
            $.operate.post(prefix + "/rollbackAudit", {appletAppId:appId});
        });
    }

    /* 发布审核 */
    function releaseAudit(appId) {
        $.modal.confirm("发布最后一个审核通过的小程序代码版本，请确认？", function () {
            $.operate.post(prefix + "/releaseAudit", {appletAppId:appId});
        });
    }

    /* 批量发布审核 */
    function mutiSubmitAudit() {
        let rows = $.table.selectColumns('shopId');
        let shopIdStr = rows.join();
        $.modal.confirm("共选择了【"+rows.length+"】个小程序，请确认是否批量生成体验版？", function () {

        });
    }

    /* 加急审核 */
    function speedupAudit(auditid,appId) {
        $.modal.confirm("加急后的小程序预计2-12小时内审完，请确认？", function () {
            $.operate.post(prefix + "/speedupAudit", {auditid:auditid,appId:appId});
        });
    }

    /* 回退上一版本 */
    function backLatest(appId) {
        $.modal.confirm("回退到上一版本，请确认？", function () {
            $.operate.post(prefix + "/backLatest", {appId:appId});
        });
    }


</script>
</body>
</html>